#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
	int N, max = -99999;//N是数组大小，max保存乘积的最大值，初始值设为一个较小的负值
	int a[1004];
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
		scanf("%d", &a[i]);
		
	for (int x = 0; x < N; x++)
	{
		for (int y = 0; y < N; y++)
		{
			for (int z = 0; z < N; z++)
			{
				if (x != y && x != z && y != z)
					max = a[x] * a[y] * a[z] > max ? max = a[x] * a[y] * a[z] : max;
			}
		}
	}
	printf("%d", max);
	return 0;
}